#pragma once

#include "ofMain.h"
#include <utility>
#include <vector>
#include "BlockCraft.h"
#include "Environment.h"
#include "Inventory.h"

#include "Item.h"

using namespace std;

class Player
{
public:
    Player(void);
    ~Player(void);

    void jump();
    void move(char direction);

    void update();
    void draw();
    void drawInventory();
    void aim();

    Item* getCurrentInventoryItem();
    int  getCurrentInventoryItemID();
    bool hasRoomInInventoryForItem(ItemParticle *itm);
    bool pickUpItem(ItemParticle *itm);
    bool deleteItemsFromInventory(int qty = 1);
    void throwItem();
    void scrollInventory(bool scrollingDown = true);
    void scrollInventoryTo(int slotNumber = 0);
    void synchronizeInventory();

    void startSwinging();
    void stopSwinging();
    bool isSwinging();

    float xPos();
    float yPos();

    string debugPos, debugVel;

    bool keyAPressed, keyDPressed;

    Item *currentItem;
    bool sneaking;

	struct block {
		int x;
		int y;
		ofPoint intercept;
		float distance;
		struct {
			int x;
			int y;
		} direction;
	};

	struct {
		block block_old;
		block block;
		ofPoint point;
		bool active;
	} target;

private:
    ofPoint pos, vel;

    float lastUpdate;

    bool hasMovementKeyDown();
    void resumeVelocity();

    const float xSpeed;
    const float gravity;
    const float jumpSpeed;
    const float reach;

	vector<block> xTargetPath;
	vector<block> yTargetPath;

    float speedModifier;

    bool swinging;

    Inventory inventory;

    // Moves the player with collision detection to avoid falling through map and walking through walls
    void moveWithCollisionDetection(void);
};
